home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-18 | 3.2 KB | 132 lines | [TEXT/IGR0] |
- #include <Value Report>
-
- |************
- | Procs to support AppendFitEquation() and the test routines...
- |************
-
- |************
- | Returns string containing a built-in curve fit equation
- | fitType is an integer selector
- Function/S GenFitEquation(fitType,nterms)
- variable fitType | 1= Gaussian, 2= Lorentzian etc
- variable nterms | need not be valid except for poly
-
- if( (fitType<1) %| (fitType>7) )
- return "GenFitEquation: unknown fit type"
- endif
-
- if(fitType==1)
- return "K0+K1*exp(-((x-K2)/K3)^2)"
- endif
- if(fitType==2)
- return "K0+K1/((x-K2)^2+K3)"
- endif
- if(fitType==3)
- return " K0+K1*exp(-K2*x)"
- endif
- if(fitType==4)
- return " K0+K1*exp(-K2*x)+K3*exp(-K4*x)"
- endif
- if(fitType==5)
- return " K0+K1*sin(K2*x+K3)"
- endif
- if(fitType==6)
- return " K0+K1*x"
- endif
-
- String s= " K0+K1*x"
- if(fitType==7)
- if( (nterms<3) %| (nterms>20) )
- return "GenFitEquation: bad number of terms for poly eqn"
- endif
- string t
- variable i=2
- do
- sprintf t,"+K%d*x^%d",i,i
- s += t
- i +=1
- while(i<nterms)
- endif
- return s
- End
-
- |************
- | Generic substring replacement routine.
- |
- Function/S SubStrReplace(theStr,beforeSub,afterSub,caseSensitive)
- string theStr | string to do the replacement on
- string beforeSub | substring in theStr to replace by ...
- string afterSub | ... this string
- variable caseSensitive | non-zero if case sensitive search is desired
-
- string tmp= theStr | working copy
- variable start | start of substring
-
- if(!caseSensitive)
- tmp= UpperStr(tmp)
- beforeSub= UpperStr(beforeSub)
- endif
- start= strsearch(tmp,beforeSub,0)
- if( start >= 0 )
- theStr[start,start+strlen(beforeSub)-1]= afterSub
- endif
- return theStr
- End
-
-
-
- |************
- | Assuming the top graph contains data that has just been fitted to a built-in function
- | this macro adds or modifies a text box containing the fitted equation using
- | the actual values from the fit. The values are rounded depending on the estimated errors.
- | The textbox is given the name 'fiteqn'.
- | If you want an extra digit of precision shown change vrsFlags to 2 (see below)
- |
- | REQUIRES: IGOR V1.2; MakeValueReportString();GenFitEquation();SubStrReplace()
- |
- Macro AppendFitEquation(fitType)
- variable fitType=1
- Prompt fitType,"Fit type:",popup,"gauss;lor;exp;dblexp;sine;line;poly"
-
- Silent 1
-
- if( (fitType<1) %| (fitType>7) )
- Abort "unknown fit type"
- endif
-
- String tmpText
- String afestr_tmp,afestr_tmp2
- Variable nterms= numpnts(W_sigma),start
- Variable vrsFlags= 4+2 | 1 digit, use E notation
- afestr_tmp= GenFitEquation(fitType,nterms)
-
- if( fitType==6 ) | fit to straight line is special...
- Make/O W_sigma={V_siga,V_sigb}
- nterms= 2
- endif
- Iterate( nterms )
- tmpText= "K"+num2istr(i)
- afestr_tmp2= MakeValueReportString(W_coef[i],W_sigma[i],0,"",vrsFlags)
- afestr_tmp= SubStrReplace(afestr_tmp,tmpText,afestr_tmp2,0)
- loop
- | may have '+-' and/or '--' as a result of the direct substitution
- start= 0
- do
- start= strsearch(afestr_tmp,"+-",start)
- if(start<0)
- break;
- endif
- afestr_tmp[start,start+1]= "-"
- while(1)
- start= 0
- do
- start= strsearch(afestr_tmp,"--",start)
- if(start<0)
- break;
- endif
- afestr_tmp[start,start+1]= "-"
- while(1)
- Textbox/C/N=fiteqn afestr_tmp
- End
-
-